package com.small.nacos.core.cluster;

import com.alibaba.nacos.common.utils.StringUtils;
import com.small.nacos.sys.env.EnvUtil;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * @Author zhoujin
 * @Date 2022/10/31 20:00
 */
@Component(value = "serverMemberManager")
public class ServerMemberManager {

    private volatile List<String> serverList = new ArrayList<>();

    @PostConstruct
    public void init() {
        String serverProperty = EnvUtil.getProperty("nacos.cluster.serverList", "");
        if (StringUtils.isNotBlank(serverProperty)) {
            List<String> serverArray = new ArrayList();
            if (serverProperty.contains(",")) {
                serverArray = Arrays.asList(serverProperty.split(","));
            } else {
                serverArray.add(serverProperty);
            }
            this.serverList = serverArray;
        }
    }

    public List<String> allMembers() {
        return serverList;
    }
}
